<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app"></div>
    <script>
        setInterval(show,1000)
        function show(){
            var app = document.getElementById("app");
            var time = "2021-10-18 8:30:00"
            // 1 获取当前时间毫秒数
            var startTime = new Date().getTime();
            // 2 获取活动开始的毫秒数
            var endTime = new Date(time).getTime();
            // 3 得到中间间隔的秒数
            var times = (endTime-startTime)/1000;
            console.log(times)
            var d = Math.floor(times/60/60/24);
            var h = Math.floor(times/60/60%24);
            var m = Math.floor(times/60%60);
            var s = Math.floor(times%60);
            var sum = handleNum(d)+":"+handleNum(h)+":"+handleNum(m)+":"+handleNum(s);
            console.log(sum)
            app.innerHTML = sum;
        }
        function handleNum(num){
            if(num<10){
                num = "0"+num;
            }
            return num;
        }
    </script>
</body>
</html>